package com.sgb.jicai.view.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.link.entity.GoodsSkuChild;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

/**
 * Time:2021/7/28
 * AUTHOR:F_Q
 * Description:
 */
public class ProductModelTwoAdaptrer extends BaseRecycleAdapter<GoodsSkuChild> {

    private CheckBox iv_materials_two;

    public ProductModelTwoAdaptrer(Context context, List<GoodsSkuChild> datas) {
        super(context, R.layout.item_jicai_product_model_two, datas);
        this.context = context;
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        iv_materials_two = holder.getItem().findViewById(R.id.iv_materials_two);
        //iv_materials_two.setChecked(datas.get(position).isOnClick());
        iv_materials_two.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                datas.get(position).setOnClick(isChecked);
                notifyDataSetChanged();
                if (checkListener != null) {
                    checkListener.onChildCheckListener(position, datas.get(position));
                }
            }
        });
    }

    @Override
    public void convert(ItemViewHolder holder, GoodsSkuChild entity) {
        holder.setBinding(BR.viewModel, entity);
    }

    private ProductModelChildCheckListener checkListener;

    public void setCheckListener(ProductModelChildCheckListener checkListener) {
        this.checkListener = checkListener;
    }

    public interface ProductModelChildCheckListener {
        void onChildCheckListener(int childPos, GoodsSkuChild child);
    }
}
